
package com.fast.fastenjoy.fileplug.domain;

import org.apache.commons.lang.StringUtils;

public class UpgradeFile {

	/**
	 * 新增操作类型
	 */
	public static final int UP_TYPE_ADD = 0;
	
	/**
	 * 更新操作类型
	 */
	public static final int UP_TYPE_UPDATE = 1;
	
	/**
	 * 删除操作类型
	 */
	public static final int UP_TYPE_REMOVE = 2;
	
	private String url;		// 下载地址
	private int upType;		// 升级类型
	private String context;	// 升级内容
	private int upSize;		// 更新大小
	
	public UpgradeFile(){}
	
	public static UpgradeFile buildUpgradeFile(String url, FileMd5Hex fileMd5Hex, int upType){
		
		if(StringUtils.isEmpty(url) || fileMd5Hex == null){
			return null;
		}
		
		UpgradeFile uf = new UpgradeFile();
		
		// URL需要转码一次，解决特殊命名文件导致请求出差
		uf.url = url;
		uf.upType = upType;
		uf.upSize = fileMd5Hex.getSize();
		
		return uf;
	}
	
	public String getUrl() {
		return url;
	}

	public int getUpType() {
		return upType;
	}

	public String getContext() {
		return context;
	}

	public int getUpSize() {
		return upSize;
	}

	public void setContext(String context) {
		this.context = context;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setUpType(int upType) {
		this.upType = upType;
	}

	public void setUpSize(int upSize) {
		this.upSize = upSize;
	}

	@Override
	public String toString() {
		
		StringBuffer sb = new StringBuffer();
		
		if(upType == UP_TYPE_ADD){
			sb.append("[新增]");
		}else if(upType == UP_TYPE_UPDATE){
			sb.append("[修改]");
		}else if(upType == UP_TYPE_REMOVE){
			sb.append("[删除]");
		}
		
		sb.append(url);
		
		return sb.toString();
	}
	
}
